Tryit Editor v2.3

Edit This Code:
<!DOCTYPE html> <html> <body> <p>In this example, we use the HTML DOM to assign an "ontimeupdate" event to an audio element. When the user starts to play the audio, or skips to a new position in the audio, a function is triggered, which will display the current position (in seconds) of the audio playback.</p> <audio id="myAudio" controls> <source src="horse.ogg" type="audio/ogg"> <source src="horse.mp3" type="audio/mpeg"> Your browser does not support the audio element. </audio> <p>Playback position: <span id="demo"></span></p> <script> // Get the audio element with id="myAudio" var aud = document.getElementById("myAudio"); // Assign an ontimeupdate event to the audio element, and execute a function if the current playback position has changed aud.ontimeupdate = function() {myFunction()}; function myFunction() { // Display the current position of the audio in a p element with id="demo" document.getElementById("demo").innerHTML = aud.currentTime; } </script> </body> <!-- Mirrored from www.w3schools.com/tags/tryit.asp?filename=tryhtml5_av_event_timeupdate2 by HTTrack Website Copier/3.x [XR&CO'2014], Fri, 23 Jan 2015 08:10:24 GMT --> </html>
Result:
Try it Yourself - © w3schools.com